/**
 * 
 */
package com.lijin.workshop.web.action;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;

import com.lijin.workshop.dao.mybatis.model.DataDic;
import com.lijin.workshop.entity.Pager;
import com.lijin.workshop.service.DataDicService;
import com.lijin.workshop.util.AssertUtil;


/**
 * @author jin
 *
 */
public final class DataDicAction extends CRUDAction<DataDic> {
	
	private static final Logger logger = Logger.getLogger(DataDicAction.class);

	private static final long serialVersionUID = 1L;
	
	@Autowired
	private DataDicService dataDicService;
	
	private DataDic dataDic;
	
	@Override
	protected Pager<DataDic> qryResultByPage() {
		logger.info("数据字典查询开始..");
		Pager<DataDic> p = new Pager<DataDic>();
		p.setPageNum(pageNum);
		p.setPageSize(pageSize);
		dataDicService.qryDataDicByPage(p, this.getQryParamMap());
		logger.info("数据字典查询完成..");
		return p;
	}
	
	/**
	 * 执行新增操作前进行校验
	 */
	@Override
	public void validateAddImpl() {
		validateDataDic();
	}
	
	/**
	 * 执行新增操作
	 */
	@Override
	public void addImpl() {
		dataDicService.addDataDic(dataDic);
	}
	
	/**
	 * 执行更新操作前进行校验
	 */
	@Override
	public void validateUpdateImpl() {
		validateDataDic();
	}
	
	/**
	 * 执行更新操作
	 */
	@Override
	public void updateImpl() {
		dataDicService.addDataDic(dataDic);
	}
	
	@Override
	protected String getColumnType() {
		return "DataDic";
	}

	private void validateDataDic() {
		AssertUtil.validateObjNull(dataDic, "待保存的数据字典对象不能为null");
		AssertUtil.validateStrBlank(dataDic.getDataTp(), "数据字典类型不能为空");
		AssertUtil.validateStrBlank(dataDic.getDataKey(), "数据字典KEY不能为空");
	}
	
	public DataDic getDataDic() {
		return dataDic;
	}

	public void setDataDic(DataDic dataDic) {
		this.dataDic = dataDic;
	}
}
